import java.util.ArrayList;
import java.util.List;

/**
 * DemoSubject
 *
 * @author Darksiderl
 * @date 2018/2/27
 */
public class DemoSubject implements Subject {

    List<Observer> observers = null;

    DemoSubject() {
        observers = new ArrayList();
    }

    @Override
    public void registerObserver(Observer o) {
        if (!observers.contains(o)) observers.add(o);
    }

    @Override
    public void unRegisterObserver(Observer o) {
        observers.remove(o);
    }

    @Override
    public void notifyAllObserver() {
        for (Observer o : observers) {
            o.update(System.currentTimeMillis() + "");
        }
    }
}
